

#include "ExtractFile.h"
#include "CommonFile.h"

#include "string.h"

//--------temps function
int Strlen(char *_string)
{
	int _temp = 0;
	while ((_string[_temp] != '\0')) _temp++;
	return _temp;
}



CExtractFile::CExtractFile()
{
}

void CExtractFile::ExtracFileByRLE(char* fileName)
{
	m_CommonFile.ReadDataFromFile(fileName);
	char* tempString = m_CommonFile.GetData();
	
	Strlen(tempString);
	int sizeTemp = 0;
	for (int i = 0; i < Strlen(tempString); ++i)
	{
		if (i % 2 == 0)
			sizeTemp += tempString[i];
	}

	char* dataAfterExtract = new char[sizeTemp];
	memset(dataAfterExtract, 0, sizeTemp);

	int indexStringDataAfterExtract = 0; //

	for (int i = 0; i < Strlen(tempString); ++i)
	{
		if (i % 2 == 0)
		for (int j = 0; j < tempString[i]; ++j)
		{
			dataAfterExtract[indexStringDataAfterExtract] = tempString[i + 1];
			indexStringDataAfterExtract++;
		}
		
	}

	m_CommonFile.WriteDataToFile(dataAfterExtract, "DataAfterExtract.txt");



}

CExtractFile::~CExtractFile()
{
}
